<template>
  <div id="sysParamSetDiv">
    <Breadcrumb :content="sysParamInfo && sysParamInfo.name" />
    <div class="bodyContent">
      <el-tabs type="border-card">
        <el-tab-pane label="系统参数">
          <vxe-toolbar perfect>
            <template #buttons>
              <div class="smallToolTitle" v-if="sysParamInfo && sysParamInfo.isLocal">本地计算机名</div>
              <div v-if="sysParamInfo && sysParamInfo.isLocal" class="computerValue">
                {{ localComputerName }}
              </div>

              <div class="smallToolTitle" v-if="sysParamInfo && sysParamInfo.classify == '1'">仪器</div>
              <vxe-select v-model="classifyCode" :filterable="true" @change="instrChangeEvent" v-if="sysParamInfo && sysParamInfo.classify == '1'">
                <vxe-option v-for="instr in instrList" :key="instr.id" :value="instr.instrCode" :label="instr.instrName"></vxe-option>
              </vxe-select>
              <div class="smallToolTitle" v-if="sysParamInfo && sysParamInfo.classify == '2'">报告单元</div>
              <vxe-select v-model="classifyCode" :filterable="true" @change="rptGroupChangeEvent" v-if="sysParamInfo && sysParamInfo.classify == '2'">
                <vxe-option v-for="rptGroup in rptGroupList" :key="rptGroup.id" :value="rptGroup.rptGroup" :label="rptGroup.rptGroupName"></vxe-option>
              </vxe-select>

              <vxe-button type="text" class="button-blue" icon="vxe-icon-refresh" content="刷新" :loading="rloading" @click="findSysParamInfoValueList" :disabled="(sysParamInfo && isEmpty(sysParamInfo.id)) || (sysParamInfo && isEmpty(sysParamInfo.paramGroupList)) || (sysParamInfo && !isEmpty(sysParamInfo.classify) && isEmpty(classifyCode))"></vxe-button>
              <vxe-button type="text" class="button-blue" icon="vxe-icon-save" content="保存" :loading="sloading" @click="saveSysParamValues" :disabled="(sysParamInfo && isEmpty(sysParamInfo.id)) || (sysParamInfo && isEmpty(sysParamInfo.paramGroupList)) || !((sysParamInfo && isEmpty(sysParamInfo.classify) && instrList.length <= 0 && rptGroupList.length <= 0) || (sysParamInfo && !isEmpty(sysParamInfo.classify) && (!instrList.length <= 0 || !rptGroupList.length <= 0))) || (sysParamInfo && sysParamInfo.isLocal && isEmpty(sltlocalComputer))"></vxe-button>
              <vxe-button type="text" class="button-blue" icon="vxe-icon-save" content="保存至本地文件" :loading="sloading" @click="saveSysParamValues2Local"></vxe-button>

              <vxe-button type="text" class="button-blue" icon="vxe-icon-copy" content="复制" v-if="sysParamInfo && sysParamInfo.classify" :loading="sloading" @click="copySysParamValues" :disabled="sysParamInfo&&sysParamInfo.paramGroupList && sysParamInfo.paramGroupList.filter((item) => !isEmpty(item.formData)).length <=0"></vxe-button>
              <vxe-button type="text" class="button-blue" icon="vxe-icon-paste" content="粘贴" v-if="sysParamInfo && sysParamInfo.classify" :loading="sloading" @click="pasteSysParamValues" :disabled="copyFormDataList.length <= 0"></vxe-button>
            </template>
          </vxe-toolbar>
          <Splitpanes class="area" vertical>
            <Pane :size="activePaneLeft" v-if="openTag1 === 0 ? false : true">
              <div class="titleNotify">当前修改计算机</div>
              <div v-if="sysParamInfo && sysParamInfo.isLocal" class="computerValue2">
                {{ sltlocalComputer }}
              </div>
              <div class="titleNotify">
                仪器列表
                <el-text class="mx-1" type="primary">需安装本地打印程序</el-text>
              </div>
              <vxe-table ref="LocalComputerTable" class="mytable-scrollbar" border="inner" align="center" height="auto" :data="LocalComputerList" :loading="rloading" :expand-config="{ expandAll: true, reserve: true }" @current-change="dictRowClick" :row-config="{ isCurrent: true, isHover: true }" :column-config="{ resizable: true }" :keyboard-config="{
                  isArrow: true,
                  isTab: true,
                  isEdit: true
                }" resizable show-overflow keep-source>
                <vxe-column field="localComputer" title="名称"> </vxe-column>
              </vxe-table>
            </Pane>
            <Pane :size="restPane">
              <div class="tableBox">
                <el-tabs v-if="sysParamInfo && sysParamInfo.paramGroupList && sysParamInfo.paramGroupList.length > 0" v-model="activeName" type="card" class="demo-tabs">
                  <!-- sysParamInfo.paramGroupList 本地参数所有数据All -->
                  <!-- group 遍历的有几个tab  -->
                  <el-tab-pane v-bind:key="idx" v-for="(group, idx) in sysParamInfo.paramGroupList" :label="`${group.code} ${group.title}`" :name="idx">
                    <el-scrollbar height="100%">
                      <!-- group.formData 遍历的选项值(单纯的tab 只要的id对象值) -->
                      <vxe-form ref="formRef" :data="group.formData">
                        <!-- group.paramFieldList 遍历的表单所有数据 包括标题+全部值 -->
                        <!-- formItm 是遍历的表单每一项 -->
                        <vxe-form-item v-for="(formItm, formIdx) in group.paramFieldList" :key="formIdx" class="padding-lr-xs" :align="formItm.align" :title="formItm.title" :field="formItm.field" :title-width="formItm.titleWidth" :title-colon="formItm.titleColon === 1" :title-asterisk="formItm.titleAsterisk === 1" :title-overflow="formItm.titleOverflow === 1" :show-title="formItm.showTitle === 1" :title-align="formItm.titleAlign" :vertical="formItm.vertical === 1" :content-class-name="formItm.contentClassName" :visible="formItm.visible === 1" :span="formItm.span">

                          <template #title>
                            <el-row>
                              <el-col :span="4">
                                <div>
                                  <span class="padding-left-xs">{{ `${formItm.code}` }}</span>
                                </div>
                              </el-col>
                              <el-col :span="20">
                                <div>
                                  <span class="padding-left-xs">{{ `${formItm.title}` }}</span>
                                </div>
                              </el-col>
                            </el-row>

                          </template>
                          <template #default="params">
                            <vxe-input v-if="formItm.compType === 'input'" v-model="params.data[formItm.id]" placeholder="请输入" clearable></vxe-input>

                            <vxe-input v-if="formItm.compType === 'date' || formItm.compType === 'datetime'" v-model="params.data[formItm.id]" :type="formItm.compType === 'date' ? 'date' : 'datetime'" placeholder="请输入" clearable transfer></vxe-input>

                            <vxe-checkbox-group v-if="formItm.compType === 'checkboxgroup'" v-model="params.data[formItm.id]">
                              <vxe-checkbox :label="itm.label" :content="itm.content" v-for="(itm, idx) in formItm.fieldOptions" :key="idx"></vxe-checkbox>
                            </vxe-checkbox-group>
                            <vxe-radio-group v-if="formItm.compType === 'radiogroup'" v-model="params.data[formItm.id]">
                              <vxe-radio :label="itm.label" :content="itm.content" v-for="(itm, idx) in formItm.fieldOptions" :key="idx"></vxe-radio>
                            </vxe-radio-group>
                            <vxe-checkbox v-if="formItm.compType === 'checkbox'" v-model="params.data[formItm.id]" :checked-value="1" :unchecked-value="0"></vxe-checkbox>
                            <vxe-input v-if="formItm.compType === 'integer'" v-model="params.data[formItm.id]" type="integer" placeholder="请输入" clearable></vxe-input>
                            <vxe-switch v-if="formItm.compType === 'switch'" v-model="params.data[formItm.id]" :open-value="1" :close-value="0" open-label="是" close-label="否"></vxe-switch>

                            <!-- 目前表单最后一条是这个 -->
                            <vxe-select v-if="formItm.compType === 'select'" v-model="params.data[formItm.id]" placeholder="请选择" transfer>
                              <vxe-option v-for="(itm, idx) in formItm.fieldOptions" :key="idx" :value="itm.label" :label="itm.content"></vxe-option>
                            </vxe-select>

                            <vxe-textarea v-if="formItm.compType === 'textarea'" v-model="params.data[formItm.id]" placeholder="请输入"></vxe-textarea>

                            <el-color-picker v-if="formItm.compType === 'color'" v-model="params.data[formItm.id]" />
                            <el-tag class="margin-lr-xs" :style="{
                                background: params.data[formItm.id] ? params.data[formItm.id] : ''
                              }" v-if="formItm.compType === 'color'">{{ params.data[formItm.id] }}</el-tag>

                            <!-- 选择动态表  -->
                            <vxe-select v-if="formItm.compType === 'sltBusTable'" v-model="params.data[formItm.id]" placeholder="可清除" :filterable="true" transfer clearable>
                              <vxe-option v-for="(tableData, index) in formItm.tableDataList" :key="index" :value="tableData[formItm.correValue]" :label="tableData[formItm.correLabel]"></vxe-option>
                            </vxe-select>
                            <!-- <vxe-select
                             v-if="formItm.compType === 'checkBusTable'" 
                             multiple v-model="params.data[formItm.id]" placeholder="可清除" transfer clearable>
                              <vxe-option v-for="(tableData, index) in formItm.tableDataList" :key="index" :value="tableData[formItm.correValue]" :label="tableData[formItm.correLabel]"></vxe-option>
                            </vxe-select> -->

                            <div v-if="formItm.compType === 'checkBusTable'">
                              <!-- dataList="formItm.tableDataList 当前多选组件的所有值 -->
                              <VxePulldownSysParamSet :url="'/api/sys/sysParamValue/findSysParamInfoByCode'" :dataObj="{paramCode: paramCode}" :paramGroup="group.code" :childIndex="formItm.correLabel" @confirmClick="(data) => confirmList(data, params.data, formItm)" :tableColumn="[{ field: formItm.correLabel, title: '名称' }]" :displayTexts="[formItm.correLabel]" :displayTextObj="formItm.valueDesc" :includeVal="formItm.correValue" />
                            </div>

                            <el-tooltip v-if="!isEmpty(formItm.remark)" :content="formItm.remark" placement="top">
                              <el-icon :size="15" style="vertical-align: middle">
                                <QuestionFilled />
                              </el-icon>
                            </el-tooltip>
                          </template>
                        </vxe-form-item>
                      </vxe-form>
                    </el-scrollbar>
                  </el-tab-pane>
                </el-tabs>
              </div>
            </Pane>
          </Splitpanes>
        </el-tab-pane>
        <el-tab-pane label="操作日志">
          <LogInfo requestUrl="/api/sys/sysParamValue"></LogInfo>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>
<script setup lang="ts">
// 引入组件区 ==========
import { ref, reactive, getCurrentInstance, onMounted } from 'vue';
import Breadcrumb from '@/components/Breadcrumb.vue';
import moment from 'moment';
import { Splitpanes, Pane } from 'splitpanes';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage'; //提示框
import VxePulldownSysParamSet from '@/components/VxePulldownSysParamSet.vue';
import { AppStore } from '../../stores/store';
import { isEmpty } from 'lodash';
import { LocPost } from '@/utils/LocRequestHelper';

import LogInfo from '@/components/LogInfo.vue'; //操作日志
import { FormItem } from 'vxe-table';

let { proxy }: any = getCurrentInstance();
let store = AppStore();
let rloading = ref(false); //最左侧仪器树形表格加载
let sloading = ref(false);
let activeName = ref(0);
let instrList: any = reactive([]); //左侧仪器下拉项
let rptGroupList: any = reactive([]);
let paramCode = '';
let classifyCode = ref('');
let localComputerName = ref('');
let sltlocalComputer = ref('');
let sysParamInfo = ref(null) as any;
let LocalComputerList: any = reactive([]);

// 默认比例
let activePaneLeft = ref(15); //最左侧小块的显示电脑列表
let restPane = ref(85); //大块的本地参数配置tab

// 打开状态
let openTag1 = ref(0); //最左侧小块的显示电脑列表默认加载状态

onMounted(() => {
  paramCode = proxy.$route.query.paramCode;
  findSysParamInfoByCode();
});

// 获取左侧仪器下拉选项数据(标题)
function findInstrSetupList() {
  instrList.length = 0; //放入数据前清空数据
  const url = '/lis/instrSetup/getInstrSetupList';
  proxy.$http
    //注意此处的数据条数
    .get(url, {
      params: { seachValue: '' }
    })
    .then((res: any) => {
      instrList.push(...res.data);
      if (instrList.length > 0) {
        classifyCode.value = instrList[0].instrCode;
        findSysParamInfoValueList();
        // setTimeout(() => {
        //   findSysParamInfoValueList();
        // }, 160);
      }
    })
    .catch((err: any) => {
      VxeMessage('获取左侧仪器表格数据异常', VxeNotifyType.error);
    });
}
function findRptGroupList() {
  rptGroupList.length = 0; //放入数据前清空数据
  const url = '/api/rptGroup/findRptGroupList';
  proxy.$http
    //注意此处的数据条数
    .get(url, {
      params: { seachValue: '' }
    })
    .then((res: any) => {
      rptGroupList.push(...res.data);
      if (rptGroupList.length > 0) {
        classifyCode.value = rptGroupList[0].rptGroup;
        proxy.$nextTick(() => {
          findSysParamInfoValueList();
        });
        // setTimeout(() => {
        //   findSysParamInfoValueList();
        // }, 160);
      }
    })
    .catch((err: any) => {
      VxeMessage('获取左侧仪器表格数据异常', VxeNotifyType.error);
    });
}

function findSysParamInfoByCode() {
  rloading.value = true;
  sysParamInfo.value = {};
  const url = '/api/sys/sysParamValue/findSysParamInfoByCode';
  let obj = { paramCode: paramCode };
  proxy.$http
    //注意此处的数据条数
    .get(url, {
      params: obj
    })
    .then((res: any) => {
      rloading.value = false;
      sysParamInfo.value = { ...res.data };
      if (!isEmpty(sysParamInfo.value.id)) {
        activePaneLeft.value = !(sysParamInfo.value && sysParamInfo.value.isComputer) ? 0 : 15;
        openTag1.value = sysParamInfo.value && sysParamInfo.value.isComputer ? 1 : 0;
        restPane.value = 100 - activePaneLeft.value;
        if (!isEmpty(sysParamInfo.value.paramGroupList)) {
          if (!isEmpty(sysParamInfo.value.paramGroupList)) {
            for (const paramGroup of sysParamInfo.value.paramGroupList) {
              paramGroup.formData = {} as any;
              for (const pField of paramGroup.paramFieldList) {
                if (pField.compType == 'sltBusTable' || pField.compType == 'checkBusTable') {
                  getTableDataList(pField);
                }
              }
            }
          }

          const clsfy = sysParamInfo.value.classify;
          if (clsfy == '1' && instrList.length <= 0) {
            findInstrSetupList();
          } else if (clsfy == '2' && rptGroupList.length <= 0) {
            findRptGroupList();
          } else if (isEmpty(clsfy)) {
            proxy.$nextTick(() => {
              findSysParamInfoValueList();
            });
            // setTimeout(() => {
            //   findSysParamInfoValueList();
            // }, 160);
          }
        }
      }
    })
    .catch((err: any) => {
      rloading.value = false;
      console.log(err);
    });
}
function saveSysParamValues2Local() {
  let classifyObjId = null;
  if (sysParamInfo.value.classify === '1') {
    let instrObj = instrList.find((item: any) => item.instrCode == classifyCode.value);
    if (instrObj) {
      classifyObjId = instrObj.id;
    }
  } else if (sysParamInfo.value.classify === '2') {
    let rptGroupObj = rptGroupList.find((item: any) => item.rptGroup == classifyCode.value);
    if (rptGroupObj) {
      classifyObjId = rptGroupObj.id;
    }
  }

  // paramGroup 是几个tab
  for (const paramGroup of sysParamInfo.value.paramGroupList) {
    let paramValueList: any = [];
    // paramGroup.paramFieldList 当前tab 遍历表单的所有数据
    // paramGroup.formData[paramField.id] 是当前字段这一条 所存放的值
    // paramField 是表单 每一项
    for (const paramField of paramGroup.paramFieldList) {
      let paramValue = {
        id: '',
        fieldId: paramField.id,
        fieldCode: paramField.field,
        classify: sysParamInfo.value.classify,
        classifyCode: classifyCode,
        classifyId: classifyObjId,
        dataType: paramField.compType,
        isLocal: sysParamInfo.value.isLocal,
        orgId: store.userInfo.orgId,
        localComputer: sltlocalComputer,
        value: ''
      };
      if (paramField.compType == 'checkboxgroup' || paramField.compType == 'checkBusTable') {
        console.log(paramGroup.formData[paramField.id]);

        paramValue.value = JSON.stringify(paramGroup.formData[paramField.id]);
      } else {
        paramValue.value = paramGroup.formData[paramField.id];
      }
      paramValueList.push(paramValue);
    }
    //paramGroup.paramValueList = paramValueList;
    if (!paramGroup.paramValueList) {
      paramGroup.paramValueList = [];
    }
    Object.assign(paramGroup.paramValueList, paramValueList);
  }
  sysParamInfo.value.paramGroupList.forEach((itm, idx) => {
    itm.paramValueList.forEach((ele) => {
      const url = (window as any).apiUrl.VUE_APP_LOCAL_PRINT_URL + `/api/LocalParams/set-local-setting?key=${ele.fieldCode}&value=${ele.value}`;
      proxy.$http
        .post(url)
        .then((res) => {
          res1 = res;
        })
        .catch((err) => {});
    });
  });
}
function saveSysParamValues() {
  sloading.value = true;
  let classifyObjId = null;
  if (sysParamInfo.value.classify === '1') {
    console.log('仪器系统参数');
    let instrObj = instrList.find((item: any) => item.instrCode == classifyCode.value);
    if (instrObj) {
      classifyObjId = instrObj.id;
    }
  } else if (sysParamInfo.value.classify === '2') {
    console.log('报告系统参数');
    let rptGroupObj = rptGroupList.find((item: any) => item.rptGroup == classifyCode.value);
    if (rptGroupObj) {
      classifyObjId = rptGroupObj.id;
    }
  }

  // paramGroup 是几个tab
  for (const paramGroup of sysParamInfo.value.paramGroupList) {
    let paramValueList: any = [];
    // paramGroup.paramFieldList 当前tab 遍历表单的所有数据
    // paramGroup.formData[paramField.id] 是当前字段这一条 所存放的值
    // paramField 是表单 每一项
    for (const paramField of paramGroup.paramFieldList) {
      let paramValue = {
        id: '',
        fieldId: paramField.id,
        classify: sysParamInfo.value.classify,
        classifyCode: classifyCode,
        classifyId: classifyObjId,
        dataType: paramField.compType,
        isLocal: sysParamInfo.value.isLocal,
        orgId: store.userInfo.orgId,
        localComputer: sltlocalComputer,
        value: ''
      };
      if (paramField.compType == 'checkboxgroup' || paramField.compType == 'checkBusTable') {
        if (!IsEmpty(paramGroup.formData[paramField.id])) {
          paramValue.value = JSON.stringify(paramGroup.formData[paramField.id]);
        } else {
          paramValue.value = null;
        }
      } else {
        paramValue.value = paramGroup.formData[paramField.id];
      }
      paramValueList.push(paramValue);
    }
    paramGroup.paramValueList = paramValueList;
  }

  const url = '/api/sys/sysParamValue/saveSysParamValueList';
  proxy.$http
    //注意此处的数据条数
    .post(url, sysParamInfo.value)
    .then((res: any) => {
      VxeMessage('保存成功', VxeNotifyType.success);
      sloading.value = false;
      findSysParamInfoValueList(); //重新获取数据
    })
    .catch((err: any) => {
      sloading.value = false;
      VxeMessage('获取字典分类列表失败', VxeNotifyType.error);
    });
}
// 仪器下拉选择 改变
function instrChangeEvent() {
  findSysParamInfoValueList();
}
function rptGroupChangeEvent() {
  findSysParamInfoValueList();
}
let pc = null;
async function findSysParamInfoValueList() {
  //如果是本地参数 则查出当前页面的计算机名称
  const isLocal = sysParamInfo.value.isLocal;
  if (isEmpty(pc) && isLocal) {
    try {
      pc = await LocPost((window as any).apiUrl.VUE_APP_LOCAL_PRINT_URL + '/api/LocalParams/get-local-pc-name', {});
      localComputerName.value = isString(pc) ? pc : '';
      sltlocalComputer.value = isString(pc) ? pc : '';
    } catch (error) {
      pc = '未知';
      console.log(error);
    }
  }
  rloading.value = true;
  const url = '/api/sys/sysParamValue/findSysParamInfoValueList';
  let obj: any = { paramCode: paramCode };
  const clsfy = sysParamInfo.value.classify;
  if (!isEmpty(clsfy)) {
    obj.classifyCode = classifyCode.value;
    obj.classify = clsfy;
  }
  if (isLocal) {
    obj.isLocal = isLocal;
    obj.localComputer = sltlocalComputer.value;
  }
  //是否显示电脑列表
  const isComputer = sysParamInfo.value.isComputer;
  if (isComputer) {
    obj.isComputer = isComputer;
  }
  proxy.$http
    //注意此处的数据条数
    .get(url, {
      params: obj
    })
    .then((res: any) => {
      if (!isEmpty(res.data.LocalComputerList)) {
        LocalComputerList.length = 0;
        LocalComputerList = res.data.LocalComputerList;
        const row = LocalComputerList.find((item) => item.localComputer == sltlocalComputer.value);

        (proxy.$refs.LocalComputerTable as any).setCurrentRow(row);
      }
      const paramValueList = res.data.fmValues;
      if (!isEmpty(sysParamInfo.value.paramGroupList)) {
        for (const paramGroup of sysParamInfo.value.paramGroupList) {
          paramGroup.formData = {} as any;
          if (!isEmpty(paramValueList)) {
            for (const paramField of paramGroup.paramFieldList) {
              const paramValue = paramValueList.find((item) => item.fieldId == paramField.id);
              if (paramValue) {
                if (paramField.compType == 'switch' || paramField.compType == 'checkbox') {
                  paramGroup.formData[paramValue.fieldId] = Number(paramValue.value);
                } else if (paramField.compType == 'checkboxgroup' || paramField.compType == 'checkBusTable') {
                  paramGroup.formData[paramValue.fieldId] = JSON.parse(paramValue.value);
                  if (paramField.compType == 'checkBusTable') {
                    if (!isEmpty(paramValue.value) && paramValue.value != 'null') {
                      const valueDescArr = [];
                      for (const str of JSON.parse(paramValue.value)) {
                        if (!isEmpty(paramField.tableDataList)) {
                          const tData = paramField.tableDataList.find((tds) => tds[paramField.correValue] == str);
                          if (!isEmpty(tData)) {
                            valueDescArr.push(tData[paramField.correLabel]);
                          }
                        }
                      }
                      paramField.valueDesc = valueDescArr.join(',');
                    } else {
                      paramField.valueDesc = '';
                    }
                  }
                } else {
                  paramGroup.formData[paramValue.fieldId] = paramValue.value;
                }
              } else {
                paramField.valueDesc = '';
              }
            }
          }
        }
      }
      rloading.value = false;
    })
    .catch((err: any) => {
      rloading.value = false;
      console.log(err);
    });
}
function isString(value: unknown): value is string {
  return typeof value === 'string';
}

// 点击字段当前行触发的事件
function dictRowClick({ row }: any) {
  (proxy.$refs.LocalComputerTable as any).setCurrentRow(row);
  sltlocalComputer.value = row.localComputer; //给最右侧传值
  findSysParamInfoValueList();
}

function getTableDataList(row: any) {
  const columNameList = [];
  columNameList.push(row.correLabel);
  columNameList.push(row.correValue);

  const url = '/api/sys/basDictTableField/getTableFieldAndDataList';
  proxy.$http
    //注意此处的数据条数
    .get(url, { params: { tableName: row.correTable, columNameList: columNameList.join(',') } })
    .then((res: any) => {
      row.tableDataList = res.data;
    })
    .catch((err: any) => {
      // VxeMessage('获取可选的字典失败',VxeNotifyType.error)
    });
}
//复制
let copyFormDataList: any = reactive([]);

function copySysParamValues() {
  copyFormDataList.length = 0;
  for (const paramGroup of sysParamInfo.value.paramGroupList) {
    for (const paramField of paramGroup.paramFieldList) {
      const map = {
        fieldId: paramField.id,
        value: paramGroup.formData[paramField.id]
      };
      copyFormDataList.push(map);
    }
  }
}
function pasteSysParamValues() {
  for (const paramGroup of sysParamInfo.value.paramGroupList) {
    for (const paramField of paramGroup.paramFieldList) {
      const copyFiledData = copyFormDataList.find((item) => item.fieldId == paramField.id);
      paramGroup.formData[copyFiledData.fieldId] = copyFiledData.value;
    }
  }
}

// function confirmList(data, paramsData, formItm1) {
//   console.log('确认事件的data',data);
//   console.log('确认事件的paramsData 插槽参数数据',paramsData);
//   console.log('确认事件的formItm1 表单每一条',formItm1);

//   // console.log(data.arr.map((item) => item[formItm.correValue]));
//   paramsData[formItm1.id] = data.arr.map((item) => item[formItm1.correValue]);
//   console.log('当前标题组', paramsData[formItm1.id])
//   formItm1.valueDesc = data.arr.map((item) => item[formItm1.correLabel]).join(',');
// }

function confirmList(data, paramsData, formItm1) {
  // console.log('传过来的data对象', data);
  // console.log('确认事件的paramsData 插槽参数数据', paramsData);
  // console.log('确认事件的formItm1 表单每一条', formItm1);

  // 针对删除情况 如果二者个数不一样，则说明有删除操作
  if (paramsData[formItm1.id] && data.arr.length !== paramsData[formItm1.id].length) {
    paramsData[formItm1.id].length = 0;
    data.arr.forEach((item) => {
      //删除后剩余的项
      const matchingFormItem = formItm1.tableDataList.find((formItem) => formItem[formItm1.correLabel] === item[formItm1.correLabel]);
      if (matchingFormItem) {
        const index = paramsData[formItm1.id].indexOf(matchingFormItem.ID);
        if (index !== -1) {
          paramsData[formItm1.id].splice(index, 1);
        }
        if (matchingFormItem[formItm1.correValue]) {
          paramsData[formItm1.id].push(matchingFormItem[formItm1.correValue]); //最后的筛选 把ID / code....（用户选择的formItm1.correValue值放进去）放进去
        }
        formItm1.valueDesc = data.arr
          .map((item) => {
            const matchingFormItem = formItm1.tableDataList.find((formItem) => formItem[formItm1.correLabel] === item[formItm1.correLabel]);
            return matchingFormItem ? matchingFormItem[formItm1.correLabel] : '';
          })
          .join(',');
      }
    });
  }
  // 初始为空的时候(直接追加)
  if (paramsData[formItm1.id] == null || paramsData[formItm1.id].length == 0) {
    paramsData[formItm1.id] = data.arr.map((item) => item[formItm1.correValue]);
    formItm1.valueDesc = data.arr.map((item) => item[formItm1.correLabel]).join(',');
  }
}

//**判断为空*/
function IsEmpty(value: any) {
  if (value === undefined || value === '' || value === null) {
    return true;
  }
  if (JSON.stringify(value) === '{}') {
    return true;
  }
  return false;
}
</script>
<style lang="scss" scoped>
#sysParamSetDiv {
  height: 100%;
  width: 100%;
  .bodyContent {
    height: calc(100% - 60px);
    .button-blue,
    .button-red {
      margin: 5px 0 5px 5px;
    }
    :deep(.el-tabs) {
      height: 100%;
      .el-tabs__content {
        height: calc(100% - 39px);
        padding: 0;
        .el-tab-pane {
          height: 100%;
        }
      }
    }
    .computerValue {
      margin: 5px;
      color: #e0103d;
    }
    .computerValue2 {
      margin: 5px;
      color: #e0103d;
      padding: 0 0 0 10px;
    }
    .area {
      background-color: $base-white;
      width: 100%;
      height: calc(100% - 40px);
      .titleNotify {
        padding: 0 0 0 10px;
      }
    }
    .tableBox {
      height: calc(100% - 40px);
      width: 50%;
    }
  }
}

.vxe-form--item.is--span .vxe-default-input:not([type='submit']):not([type='reset']),
.vxe-form--item.is--span .vxe-default-textarea,
.vxe-form--item.is--span .vxe-default-select,
.vxe-form--item.is--span .vxe-input,
.vxe-form--item.is--span .vxe-textarea,
.vxe-form--item.is--span .vxe-select {
  width: 90%;
  margin: 0 5px 0 0;
}
</style>
